package com.gzy.xuexiziliao.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gzy.xuexiziliao.common.result.PageResult;
import com.gzy.xuexiziliao.mapper.ReviewMapper;
import com.gzy.xuexiziliao.pojo.entity.Review;
import com.gzy.xuexiziliao.pojo.entity.Student;
import com.gzy.xuexiziliao.service.ReviewService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RequiredArgsConstructor
@Service
public class ReviewServiceImpl implements ReviewService {
    private final ReviewMapper reviewMapper;
    @Override
    public void addreview(Review review) {
        review.setUpdateTime(LocalDateTime.now());
        review.setCreateTime(LocalDateTime.now());
        reviewMapper.addreview(review);
    }

    @Override
    public Review getReview(Integer reviewId) {
        Review review = reviewMapper.getReview(reviewId);
        if (review != null){
            return review;
        }
        return null;
    }

    @Override
    public PageResult page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        //1.设置分页参数
        PageHelper.startPage(page, pageSize);
        //2.执行查询
        List<Review> studentsList = reviewMapper.list(name, gender, begin, end);
        Page<Review> p = (Page<Review>) studentsList;
        //3.封装对象
        PageResult pageResult = new PageResult(p.getTotal(), p.getResult());
        return pageResult;

    }
}
